/*
* @Author: syq
* @Date:   2017-12-04 16:34:17
* @Last Modified by:   shenyanqiu
* @Last Modified time: 2017-12-05 19:55:25
*/
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'dva';
import styles from './index.less';
import { Page } from 'components';
import queryString from 'query-string';
import { Operation, List } from './Components';
import TopRightButton from './../../components/TopOperation/TopRightButton';

class AddressList extends React.Component {
  static propTypes = {
    loading: PropTypes.object,
    dispatch: PropTypes.func,
    addressList: PropTypes.object,
    location: PropTypes.object,
  };
  render () {
    // const { loading } = this.props;
    const { loading, location, addressList, dispatch } = this.props;
    location.query = queryString.parse(location.search);
    const { list, pagination } = addressList;
    const listProps = {
      dataSource: list,
      loading: loading.effects['addressList/getAddressList'],
      pagination,
      // 改变分页page
      onChange (_pagination) {
        const { query, pathname } = location;
        dispatch({
          type: 'addressList/getAddressList',
          payload: {
            ...query,
            current: _pagination.current,
            pageSize: _pagination.pageSize,
          },
        });
      },
      // 标位离职
      onSignTo (id, record) {
        dispatch({
          type: 'addressList/onSignModal',
          payload: {
            id,
          },
        });
      },
    };
    // 点击搜索触发请求数据
    function SearchData (data) {
      dispatch({
        type: 'addressList/searchData',
        payload: {
          formData: data,
        },
      });
    }
    // 点击导出数据
    function clickHandle () {
      console.log('导出操作');
    }
    return (
      <Page loading={loading.models.addressList}>
        <Operation SearchData={SearchData} />
        <List {...listProps} />
        <TopRightButton contentText="导出数据" clickHandle={clickHandle} />
      </Page>
    );
  }
}


export default connect(({ loading, addressList }) => ({ loading, addressList }))(AddressList);
